Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge master to stage from master #1697

Open
wants to merge 1 commit into
base: staging
Choose a base branch
from

Conversation

ae2079
Copy link
Contributor

@ae2079 ae2079 commented Jul 17, 2024

Summary by CodeRabbit

  • New Features

    • Introduced support for additional donation box usage and transaction hash tracking in draft donations.
  • Improvements

    • Enhanced donation reporting with new functions to count unique donors and sum donation values.
    • Added ability to find stable coin donations without price details.
    • Improved synchronization of donation statuses with blockchain networks.
    • Enhanced project views with better donation summary and matching estimates.
  • Bug Fixes

    • Addressed issues with outdated stable coin donation prices.
  • Tests

    • Updated test cases to cover new functionalities and ensure robustness.

Copy link
Contributor

coderabbitai bot commented Jul 17, 2024

Walkthrough

The updates introduce several enhancements and refactorings across the codebase. Key changes include adding new columns to the draft_donation table, refining functions related to donation metrics, and incorporating new functionalities for handling stable coin donations and updating donation prices. The changes also enhance caching mechanisms and optimize query logic, improving performance and maintainability.

Changes

File/Path Change Summary
migration/1719887968639...DraftDonations.ts Added useDonationBox and relevantDonationTxHash columns to draft_donation table without conditional checks.
src/repositories/donationRepository.test.ts Updated tests for donation-related functions, added findStableCoinDonationsWithoutPrice, and adjusted functions for donation metrics
src/repositories/donationRepository.ts Refactored donation metric functions, added imports, optimized queries, and renamed various methods for clarity.
src/services/donationService.ts Added functions for updating old donations prices, refreshing views, and syncing donation status, along with relevant imports.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant DonationRepository
    participant DonationService
    participant Database

    User->>+DonationRepository: countUniqueDonors(projectId)
    DonationRepository->>Database: Query unique donors count
    Database-->>DonationRepository: Result
    DonationRepository-->>-User: Count of unique donors

    User->>+DonationService: updateOldStableCoinDonationsPrice()
    DonationService->>DonationRepository: findStableCoinDonationsWithoutPrice()
    DonationRepository->>Database: Query stable coin donations without price
    Database-->>DonationRepository: Result
    DonationRepository-->>DonationService: List of donations
    DonationService->>Database: Update donations with historic prices
    Database-->>DonationService: Update result
    DonationService-->>-User: Update complete
Loading
sequenceDiagram
    participant Migration
    participant Database

    Migration->>+Database: Add columns to draft_donation table
    Database-->>-Migration: Columns added
Loading

Poem

In the realm of code, with changes vast,
Donations tracked, from first to last.
Columns added, queries refined,
Metrics counted, neatly aligned.
Stable coins now have their place,
In this digital donation space.
🐇✨💻


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f14a053 and 71ce0d1.

Files selected for processing (4)
  • migration/1719887968639-addUseDonationBoxToDraftDonations.ts (1 hunks)
  • src/repositories/donationRepository.test.ts (23 hunks)
  • src/repositories/donationRepository.ts (5 hunks)
  • src/services/donationService.ts (11 hunks)
Additional context used
Biome
src/repositories/donationRepository.test.ts

[error] 388-388: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 393-393: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 403-403: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 416-416: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 425-425: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

Additional comments not posted (28)
migration/1719887968639-addUseDonationBoxToDraftDonations.ts (2)

7-14: LGTM! Columns added correctly.

The useDonationBox column is added as a boolean with a default value of false, and the relevantDonationTxHash column is added as a varchar. Both columns are nullable.


17-24: LGTM! Columns added correctly.

The relevantDonationTxHash column is added as a varchar and is nullable.

src/repositories/donationRepository.ts (7)

6-9: LGTM! Imports added correctly.

The added imports are relevant and correctly used within the file.


167-174: LGTM! Caching logic added correctly.

The caching logic for donationsTotalAmountPerDateRange is correctly implemented with a cache key and duration.


252-259: LGTM! Caching logic added correctly.

The caching logic for donationsNumberPerDateRange is correctly implemented with a cache key and duration.


471-478: LGTM! Function renamed and refactored correctly.

The function countUniqueDonorsForRound is correctly renamed from getProjectQfRoundStats and refactored to use getProjectDonationsSqrtRootSum.


480-501: LGTM! Function renamed and refactored correctly.

The function sumDonationValueUsdForQfRound is correctly renamed from sumDonationValueUsdForQfRound and refactored to use ProjectEstimatedMatchingView.


504-517: LGTM! Function refactored correctly.

The function countUniqueDonors is correctly refactored to use ProjectDonationSummaryView.


519-531: LGTM! Function refactored correctly.

The function sumDonationValueUsd is correctly refactored to use ProjectDonationSummaryView.

src/services/donationService.ts (7)

21-21: LGTM! Imports added correctly.

The added imports are relevant and correctly used within the file.

Also applies to: 25-25


183-188: LGTM! Function modified correctly.

The function updateDonationByTransakData is correctly modified to call updateTotalDonationsOfProject.


190-210: LGTM! Function implemented correctly.

The function updateTotalDonationsOfProject is correctly implemented to update the total donations of a project.


243-280: LGTM! Function implemented correctly.

The function updateOldGivDonationsPrice is correctly implemented to update the price of old GIV donations.


282-302: LGTM! Function implemented correctly.

The function updateOldStableCoinDonationsPrice is correctly implemented to update the price of old stable coin donations.


364-380: LGTM! Function modified correctly.

The function syncDonationStatusWithBlockchainNetwork is correctly modified to call refreshProjectDonationSummaryView.


Line range hint 484-583:
LGTM! Function implemented correctly.

The function insertDonationsFromQfRoundHistory is correctly implemented to insert donations from QF round history.

src/repositories/donationRepository.test.ts (12)

17-18: Imports look good.

The updated imports for countUniqueDonors, findStableCoinDonationsWithoutPrice, and sumDonationValueUsd are correct and necessary for the test cases.

Also applies to: 23-23, 27-28


30-30: Import statement approved.

The import for updateOldStableCoinDonationsPrice from donationService is correct and necessary for the test cases.


34-37: Import statements approved.

The imports for refreshProjectDonationSummaryView and refreshProjectEstimatedMatchingView from projectViewsService are correct and necessary for the test cases.


39-39: Import statement approved.

The import for NETWORK_IDS from provider is correct and necessary for the test cases.


51-54: New test cases for findStableCoinDonationsWithoutPrice look good.

The test cases are correctly implemented and comprehensive.


208-208: Updates to test cases approved.

The updates to include refreshProjectDonationSummaryView are correct and necessary.

Also applies to: 268-268


579-584: Updates to test cases for countUniqueDonorsForRound look good.

The updates are correct and necessary to ensure comprehensive test coverage.

Also applies to: 631-636, 673-681, 719-726, 786-793


807-810: Updates to test cases for countUniqueDonors look good.

The updates are correct and necessary to ensure comprehensive test coverage.

Also applies to: 831-833, 855-858, 900-904


927-932: Updates to test cases for sumDonationValueUsdForQfRound look good.

The updates are correct and necessary to ensure comprehensive test coverage.

Also applies to: 984-992, 1032-1039, 1076-1087, 1127-1133, 1200-1207


1222-1223: Updates to test cases for sumDonationValueUsd look good.

The updates are correct and necessary to ensure comprehensive test coverage.

Also applies to: 1261-1265, 1316-1320


Line range hint 1354-1354:
Updates to test cases for isVerifiedDonationExistsInQfRound look good.

The updates are correct and necessary to ensure comprehensive test coverage.


Line range hint 1405-1405:
Updates to test cases for findRelevantDonations look good.

The updates are correct and necessary to ensure comprehensive test coverage.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Comment on lines +382 to +467
function findStableCoinDonationsWithoutPriceTestCases() {
it('should just return stable coin donations without price', async () => {
const project = await saveProjectDirectlyToDb(createProjectData());
const donor = await saveUserDirectlyToDb(generateRandomEtheriumAddress());

const donationData1 = { ...createDonationData(), currency: 'USDC' };
delete donationData1.valueUsd;

const donationData2 = { ...createDonationData(), currency: 'USDC' };

const donationData3 = { ...createDonationData(), currency: 'USDT' };
delete donationData3.valueUsd;

const donationData4 = { ...createDonationData(), currency: 'USDT' };
donationData4.currency = 'USDT';

const donationData5 = {
...createDonationData(),
currency: 'WXDAI',
transactionNetworkId: NETWORK_IDS.XDAI,
};
delete donationData5.valueUsd;

const donationData6 = {
...createDonationData(),
currency: 'WXDAI',
transactionNetworkId: NETWORK_IDS.XDAI,
};

const donationData7 = {
...createDonationData(),
currency: 'WXDAI',
transactionNetworkId: NETWORK_IDS.XDAI,
};
delete donationData7.valueUsd;

const donationData8 = {
...createDonationData(),
currency: 'WXDAI',
transactionNetworkId: NETWORK_IDS.XDAI,
};

const donationData9 = createDonationData();
delete donationData9.valueUsd;

await saveDonationDirectlyToDb(donationData1, donor.id, project.id);
await saveDonationDirectlyToDb(donationData2, donor.id, project.id);
await saveDonationDirectlyToDb(donationData3, donor.id, project.id);
await saveDonationDirectlyToDb(donationData4, donor.id, project.id);
await saveDonationDirectlyToDb(donationData5, donor.id, project.id);
await saveDonationDirectlyToDb(donationData6, donor.id, project.id);
await saveDonationDirectlyToDb(donationData7, donor.id, project.id);
await saveDonationDirectlyToDb(donationData8, donor.id, project.id);
await saveDonationDirectlyToDb(donationData9, donor.id, project.id);

const donations = await findStableCoinDonationsWithoutPrice();
assert.equal(donations.length, 4);
assert.isOk(
donations.find(
donation => donation.transactionId === donationData1.transactionId,
),
);
assert.isOk(
donations.find(
donation => donation.transactionId === donationData3.transactionId,
),
);
assert.isOk(
donations.find(
donation => donation.transactionId === donationData5.transactionId,
),
);
assert.isOk(
donations.find(
donation => donation.transactionId === donationData7.transactionId,
),
);

await updateOldStableCoinDonationsPrice();

// Shoud fill valuUsd of all stable coin donations
const stableDonationsWithoutPrice =
await findStableCoinDonationsWithoutPrice();
assert.isEmpty(stableDonationsWithoutPrice);
});
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using the delete operator for performance reasons.

The delete operator can impact performance. Instead, consider setting the property to undefined.

- delete donationData1.valueUsd;
+ donationData1.valueUsd = undefined;

- delete donationData3.valueUsd;
+ donationData3.valueUsd = undefined;

- delete donationData5.valueUsd;
+ donationData5.valueUsd = undefined;

- delete donationData7.valueUsd;
+ donationData7.valueUsd = undefined;

- delete donationData9.valueUsd;
+ donationData9.valueUsd = undefined;
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function findStableCoinDonationsWithoutPriceTestCases() {
it('should just return stable coin donations without price', async () => {
const project = await saveProjectDirectlyToDb(createProjectData());
const donor = await saveUserDirectlyToDb(generateRandomEtheriumAddress());
const donationData1 = { ...createDonationData(), currency: 'USDC' };
delete donationData1.valueUsd;
const donationData2 = { ...createDonationData(), currency: 'USDC' };
const donationData3 = { ...createDonationData(), currency: 'USDT' };
delete donationData3.valueUsd;
const donationData4 = { ...createDonationData(), currency: 'USDT' };
donationData4.currency = 'USDT';
const donationData5 = {
...createDonationData(),
currency: 'WXDAI',
transactionNetworkId: NETWORK_IDS.XDAI,
};
delete donationData5.valueUsd;
const donationData6 = {
...createDonationData(),
currency: 'WXDAI',
transactionNetworkId: NETWORK_IDS.XDAI,
};
const donationData7 = {
...createDonationData(),
currency: 'WXDAI',
transactionNetworkId: NETWORK_IDS.XDAI,
};
delete donationData7.valueUsd;
const donationData8 = {
...createDonationData(),
currency: 'WXDAI',
transactionNetworkId: NETWORK_IDS.XDAI,
};
const donationData9 = createDonationData();
delete donationData9.valueUsd;
await saveDonationDirectlyToDb(donationData1, donor.id, project.id);
await saveDonationDirectlyToDb(donationData2, donor.id, project.id);
await saveDonationDirectlyToDb(donationData3, donor.id, project.id);
await saveDonationDirectlyToDb(donationData4, donor.id, project.id);
await saveDonationDirectlyToDb(donationData5, donor.id, project.id);
await saveDonationDirectlyToDb(donationData6, donor.id, project.id);
await saveDonationDirectlyToDb(donationData7, donor.id, project.id);
await saveDonationDirectlyToDb(donationData8, donor.id, project.id);
await saveDonationDirectlyToDb(donationData9, donor.id, project.id);
const donations = await findStableCoinDonationsWithoutPrice();
assert.equal(donations.length, 4);
assert.isOk(
donations.find(
donation => donation.transactionId === donationData1.transactionId,
),
);
assert.isOk(
donations.find(
donation => donation.transactionId === donationData3.transactionId,
),
);
assert.isOk(
donations.find(
donation => donation.transactionId === donationData5.transactionId,
),
);
assert.isOk(
donations.find(
donation => donation.transactionId === donationData7.transactionId,
),
);
await updateOldStableCoinDonationsPrice();
// Shoud fill valuUsd of all stable coin donations
const stableDonationsWithoutPrice =
await findStableCoinDonationsWithoutPrice();
assert.isEmpty(stableDonationsWithoutPrice);
});
}
function findStableCoinDonationsWithoutPriceTestCases() {
it('should just return stable coin donations without price', async () => {
const project = await saveProjectDirectlyToDb(createProjectData());
const donor = await saveUserDirectlyToDb(generateRandomEtheriumAddress());
const donationData1 = { ...createDonationData(), currency: 'USDC' };
donationData1.valueUsd = undefined;
const donationData2 = { ...createDonationData(), currency: 'USDC' };
const donationData3 = { ...createDonationData(), currency: 'USDT' };
donationData3.valueUsd = undefined;
const donationData4 = { ...createDonationData(), currency: 'USDT' };
donationData4.currency = 'USDT';
const donationData5 = {
...createDonationData(),
currency: 'WXDAI',
transactionNetworkId: NETWORK_IDS.XDAI,
};
donationData5.valueUsd = undefined;
const donationData6 = {
...createDonationData(),
currency: 'WXDAI',
transactionNetworkId: NETWORK_IDS.XDAI,
};
const donationData7 = {
...createDonationData(),
currency: 'WXDAI',
transactionNetworkId: NETWORK_IDS.XDAI,
};
donationData7.valueUsd = undefined;
const donationData8 = {
...createDonationData(),
currency: 'WXDAI',
transactionNetworkId: NETWORK_IDS.XDAI,
};
const donationData9 = createDonationData();
donationData9.valueUsd = undefined;
await saveDonationDirectlyToDb(donationData1, donor.id, project.id);
await saveDonationDirectlyToDb(donationData2, donor.id, project.id);
await saveDonationDirectlyToDb(donationData3, donor.id, project.id);
await saveDonationDirectlyToDb(donationData4, donor.id, project.id);
await saveDonationDirectlyToDb(donationData5, donor.id, project.id);
await saveDonationDirectlyToDb(donationData6, donor.id, project.id);
await saveDonationDirectlyToDb(donationData7, donor.id, project.id);
await saveDonationDirectlyToDb(donationData8, donor.id, project.id);
await saveDonationDirectlyToDb(donationData9, donor.id, project.id);
const donations = await findStableCoinDonationsWithoutPrice();
assert.equal(donations.length, 4);
assert.isOk(
donations.find(
donation => donation.transactionId === donationData1.transactionId,
),
);
assert.isOk(
donations.find(
donation => donation.transactionId === donationData3.transactionId,
),
);
assert.isOk(
donations.find(
donation => donation.transactionId === donationData5.transactionId,
),
);
assert.isOk(
donations.find(
donation => donation.transactionId === donationData7.transactionId,
),
);
await updateOldStableCoinDonationsPrice();
// Shoud fill valuUsd of all stable coin donations
const stableDonationsWithoutPrice =
await findStableCoinDonationsWithoutPrice();
assert.isEmpty(stableDonationsWithoutPrice);
});
}
Tools
Biome

[error] 388-388: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 393-393: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 403-403: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 416-416: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 425-425: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant